/*
 * log in page
 * @author: Ammar ahmed
 * 
 * The first page where the student logs in
 */

package com.uncc.sensingsuite;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnKeyListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Login extends Activity
{
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);

		Button submit = (Button) findViewById(R.id.submitUsernamePassword);
		final EditText editUser = (EditText) findViewById(R.id.editText1);
		final EditText editPass = (EditText) findViewById(R.id.editText2);

		
		
		editUser.setOnKeyListener(new OnKeyListener() {
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				// If the event is a key-down event on the "enter" button
				if ((event.getAction() == KeyEvent.ACTION_DOWN)
						&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
					// Perform action on key press
					Toast.makeText(Login.this, editUser.getText(),
							Toast.LENGTH_SHORT).show();
					return true;
				}
				return false;
			}
		});

		editPass.setOnKeyListener(new OnKeyListener() {
			public boolean onKey(View v, int keyCode, KeyEvent event) {
				// If the event is a key-down event on the "enter" button
				if ((event.getAction() == KeyEvent.ACTION_DOWN)
						&& (keyCode == KeyEvent.KEYCODE_ENTER)) {
					// Perform action on key press
					Toast.makeText(Login.this, editPass.getText(),
							Toast.LENGTH_SHORT).show();
					return true;
				}
				return false;
			}
		});


		
		submit.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				//Toast.makeText(sensingsuiteweb.this, editUser.getText(),
					//	Toast.LENGTH_SHORT).show();
				

				String u = "abc";
				String p = "123";	
				EditText  x = (EditText) editUser.findViewById(R.id.editText1);
				EditText y = (EditText) editPass.findViewById(R.id.editText2);
				
				boolean a1 = x.getText().toString().equals(u);
				boolean a2 = y.getText().toString().equals(p);
				/**/
				if (a1 && a2)
				{
					Toast.makeText(Login.this, "Login Successful",Toast.LENGTH_SHORT).show();
	        		Intent myintent = new Intent(Login.this, sensingsuite.class);
	        		startActivity(myintent);
				}
				else
				{
					Toast.makeText(Login.this, editUser.getText(),Toast.LENGTH_SHORT).show();
					Toast.makeText(Login.this, editPass.getText(),Toast.LENGTH_SHORT).show();
				}

				// go to the next page
			}
		});
	}
}